package tests;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import org.junit.Test;

import firewall.AccionLog;
import firewall.Paquete;

public class testLogueo{

	@Test
	public void grabaDosLogs() throws IOException {
		
		AccionLog accion = new AccionLog("C:\\Users\\Mauro\\Desktop\\TADP\\","testLog.log");
		
		FileReader fdesc = null;

		long lNumeroLineasAnterior = 0;
		long lNumeroLineas = 0;
		
		try  {

			fdesc = new FileReader("C:\\Users\\Mauro\\Desktop\\TADP\\testLog.log");
			BufferedReader bf = new BufferedReader(fdesc);
			
			while ((bf.readLine())!=null) {
				lNumeroLineasAnterior++;
			}
			
			Paquete paquete = new Paquete("200.90.80.70","192.168.2.1",8080);
			accion.ejecutarAccionPara(paquete);
			
			paquete = new Paquete("190.28.95.153","192.168.2.2",8080);
			accion.ejecutarAccionPara(paquete);
			
			while ((bf.readLine())!=null) {
				lNumeroLineas++;
			}
			
			bf.close();
			
		}catch (IOException e) {
			throw e;
		}finally{
			// Cierra el archivo
			if(fdesc != null){
				try{
					fdesc.close();
				}catch (IOException e) {}
			}
		}
		
		assertEquals(2,lNumeroLineas);

	}

}
